package com.forezp.web;

import com.forezp.data.Company;
import com.forezp.data.User;
import com.forezp.service.SchedualServiceGo;
import com.forezp.service.SchedualServiceHi;
import com.netflix.hystrix.contrib.javanica.annotation.HystrixCommand;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 * Created by yangfei on 2017/4/6.
 */
@RestController
public class HiController {

    @Autowired
    SchedualServiceHi schedualServiceHi;

    @Autowired
    SchedualServiceGo schedualServiceGo;

    @RequestMapping(value = "/hi",method = RequestMethod.GET)
    @HystrixCommand(fallbackMethod = "callRecommendFallback")
    public String sayHi(@RequestParam String name){
        User user = new User();
        user.setNumber(1);
        user.setUsername(name);
        user.setPassword(name+1);
        return schedualServiceHi.sayHiFromClientOne(user).toString();
    }

    public String callRecommendFallback(String name) {
        return "sayHiFromClientOne+接口异常。。。";
    }

    @RequestMapping(value = "/go",method = RequestMethod.GET)
    public String sayGo(@RequestParam String name){
        Company company = new Company();
        company.setId(3);
        company.setAddr("中国杭州");
        return schedualServiceGo.sayHiFromClientGo(company).toString();
    }

    @RequestMapping(value = "/gh",method = RequestMethod.GET)
    public String sayGH(@RequestParam String name){
        Company company = new Company();
        company.setId(3);
        company.setAddr("中国杭州");

        User user = new User();
        user.setNumber(1);
        user.setUsername(name);
        user.setPassword(name+1);
        User uv = schedualServiceHi.sayHiFromClientOne(user);
        Company cy = schedualServiceGo.sayHiFromClientGo(company);
        return cy.toString()+uv;
    }
}
